﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LinqPractice01
{
    class Program
    {
        static void Main(string[] args)
        {
            List<Todo> mList = new List<Todo>();
            mList.Add(new Todo { TodoId = 1, Text = "Learn LINQ", TimeSubmitted = DateTime.Today.AddDays(-6), TimeCompleted=DateTime.Today.AddDays(-2), UserId = 1, UserName = "Sally" });
            mList.Add(new Todo { TodoId = 2, Text = "Learn C#", TimeSubmitted = DateTime.Today.AddDays(-5), UserId = 2, UserName = "Joe" });
            mList.Add(new Todo { TodoId = 3, Text = "Learn JS", TimeSubmitted = DateTime.Today.AddDays(-2), TimeCompleted = DateTime.Today.AddDays(-1), UserId = 3, UserName = "Julio" });
            mList.Add(new Todo { TodoId = 4, Text = "Learn Spanish", TimeSubmitted = DateTime.Today.AddDays(-13),UserId = 1, UserName = "Sally"  });
            mList.Add(new Todo { TodoId = 2, Text = "Learn C#", TimeSubmitted = DateTime.Today.AddDays(-5), UserId = 2, UserName = "Joe" });
            mList.Add(new Todo { TodoId = 5, Text = "Learn JAVA", TimeSubmitted = DateTime.Today.AddDays(-5), TimeCompleted = DateTime.Now, UserId = 3, UserName = "Julio" });
            mList.Add(new Todo { TodoId = 6, Text = "Learn ASP.NET", TimeSubmitted = DateTime.Today.AddDays(-2), UserId = 1, UserName = "Sally" });
            mList.Add(new Todo { TodoId = 7, Text = "Do not learn Actionscript", TimeSubmitted = DateTime.Now, UserId = 3, UserName = "Julio" });

            //1 Get by Id...
            int id = 4;
            var query = mList
                .Where(t => t.TodoId == id)
                .ToList();
            //2 Get all Todos that are NOT completed...
            var notCompleted = mList
                .Where(t => t.TimeCompleted == null)
                .Select(e => e.Text).ToList();

            //get lastest 3..
            var latest = mList
                .OrderByDescending(t => t.TimeSubmitted)
                .Take(3)
                .ToList();
                

            //get all Todos from 5 days ago

            var checker = DateTime.Today.AddDays(-5);

            var fiveDaysAgo = mList
                .Where(t => t.TimeSubmitted == checker)
                .ToList();

            //get all Todos for user Sally

            var user = mList
                .Where(t => t.UserName == "Sally" || t.UserName =="Joe")
                .ToList();
           

            foreach (var item in user) {
                Console.WriteLine(item.Text);
            }

            Console.ReadLine();

        }
    }
}